package cn.htsyb.synergy.orm.jpa.criterion;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lakeside hubin_yuan.410@hotmail.com
 * @version V1.0.0
 * @date 2022/5/11
 * @since 1.0
 */
public class OrderBuilder<T> {
    private final List<OrderExpress> expresses = new ArrayList<>();

    public static <T> OrderBuilder<T> instance() {
        return new OrderBuilder<T>();
    }

    public static <T> OrderBuilder<T> instance(List<OrderExpress> expresses) {
        return new OrderBuilder<T>().addAllOrders(expresses);
    }

    public <T> OrderBuilder<T> addAllOrders(List<OrderExpress> expresses) {
        this.expresses.addAll(expresses);
        return (OrderBuilder<T>) this;
    }

    public <T> OrderBuilder<T> addOrders(boolean condition, String property, OrderExpress.Direction direction) {

        if (condition) {
            expresses.add(new OrderExpress(property, direction));
        }
        return (OrderBuilder<T>) this;
    }

    public List<OrderExpress> build() {
        return expresses;
    }
}
